package com.gistmap.sideline.web;

import com.gistmap.sideline.payload.CreditRequest;
import com.gistmap.sideline.payload.Result;
import com.gistmap.sideline.payload.VerifiedRequest;
import com.gistmap.sideline.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.io.IOException;

@RestController
@RequestMapping("/api/user")
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("/verifired")
    public Result verified(@Valid @RequestBody VerifiedRequest request) {
        try {
            return userService.verified(request);
        } catch (IOException e) {
            e.printStackTrace();
            return new Result().fail(e.getMessage());
        }
    }

    /**
     * 互评
     * @param userId
     * @param request
     * @return
     */
    @PostMapping("/comment/{userId}")
    public Result comment(@PathVariable Long userId,
                          @Valid @RequestBody CreditRequest request) {

        userService.comment( userId, request);
        return new Result().success("评价成功!");
    }
}
